package org.example.pack1023.reflect;

import java.lang.reflect.Method;
import java.util.Arrays;

public class DemoD {
    public static void main(String[] args) throws Exception {
        Class c = Class.forName("org.example.pack1023.reflect.ChildClass");
        //获取方法
        Method[] methods1 = c.getMethods();
        Method[] methods2 = c.getDeclaredMethods();
        System.out.println(Arrays.toString(methods1));
        System.out.println(Arrays.toString(methods2));

        Method method1 = c.getMethod("c",Integer.TYPE,String.class);
        Method method2 = c.getDeclaredMethod("d");
        System.out.println(method1);
        //调用方法--对象点方法
        Object obj = c.newInstance();
        //Object 返回值 = 方法.invoke(对象,实参列表);
        Object result = method1.invoke(obj,3,"ss");
        System.out.println(result);
        System.out.println("-----------------------------------------");
        //设置权限（是否能调用私有属性，true）
        method2.setAccessible(true);
        Object result2 = method2.invoke(obj);
        System.out.println(result2);

    }
}
